<template>
	<view class="">
		<dcustom bgColor="bg-gradual-blue" :isBack="true" :isArrow="true">
			<block slot="backText">返回</block>
			<block slot="content">修改密码</block>
		</dcustom>
		<view class="e-container">
			<form @submit="formSubmit" class="login-form">
				<view class="section" :class="inputIndex==1?'solid-bottom-blue':'' ">
					<!-- <view class="section__title">旧密码</view> -->
					<input name="oldpwd" @focus="setActive(1)" placeholder="旧密码"  />
				</view>
				<view class="section" :class="inputIndex==2?'solid-bottom-blue':'' ">
					<!-- <view class="section__title">旧密码</view> -->
					<input name="newpwd" @focus="setActive(2)" type="password" placeholder="新密码"  />
				</view>
				<view class="section" :class="inputIndex==3?'solid-bottom-blue':'' ">
					<!-- <view class="section__title">旧密码</view> -->
					<input name="newpwd2" @focus="setActive(3)" type="password" placeholder="确认新密码"  />
				</view>
			
				<view class="btn-area" hover-class="e-hover-btn">
					<button formType="submit" class="login-btn" type="primary">提交</button>
				</view>
			</form>
		</view>
		</vie>
	</view>
</template>

<script>
	import api from '../../common/api.js'
	import md5 from '../../common/md5.js'
	let _self;
	export default {
		data() {
			return {
				userId: '',
				userName: '',
				baseUrl:'',
				inputIndex:6
			};
		},
		onLoad: function(params) {
			_self = this;
			uni.getStorage({
				key: 'baseUrl',
				success: function(res) {
					_self.baseUrl = res.data;
				}
			});
			uni.getStorage({
				key: 'userId',
				success: function(res) {
					_self.userId = res.data
				}
			});
			uni.getStorage({
				key: 'userName',
				success: function(res) {
					_self.userName = res.data
				}
			});
		},
		methods: {
			setActive(i){
				_self.inputIndex = i 
			},
			formSubmit(e) {
				let getFormData = e.detail.value;
				var dataObj = {
					userName: _self.userId,
					oldPwd: md5.hex_md5(getFormData.oldpwd),
					newPwd: md5.hex_md5(getFormData.newpwd)
				}
				if (getFormData.newpwd != getFormData.newpwd2) {
					return uni.showToast({
						title: '新密码输入不一致',
						icon: 'none'
					});
				}
				console.log(JSON.stringify(dataObj))
				this.axios({
					url: api.apiPublic.setPassword ,
					data: dataObj ,
					isLoading: 1
				}).then(res=>{
					let { Result } = res ;
					this.$utils.tips('提交成功')
					this.$utils.delayBack();
				})
				// console.log(JSON.stringify(e.detail.value))
			}
		}
	}
</script>

<style scoped="">
	.section {
		margin: 40upx;
		border-bottom: 1upx solid #aaa;
	}

	.btn-area {
		margin: 60upx 40upx 0upx 40upx;
	}
</style>
